package com.tim.app.ui.adapter.found;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.widget.RatioImageView;
import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.MusicAlbum;
import com.tim.app.util.BitmapLoader;

import java.util.List;


/**
 * 音乐专辑的适配器
 */
public class MusciAlbumItemAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, MusicAlbum> {

    static final String TAG = "MusciAlbumItemAdapter";

    private Context mContext;


    public MusciAlbumItemAdapter(Context mContext, List<MusicAlbum> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_music_album, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder mHolder, int position, final MusicAlbum data) {

        if (null == data)
            return;
        final ViewHolder holder = (ViewHolder) mHolder;
        if (!TextUtils.isEmpty(data.getImage())) {
            BitmapLoader.ins().loadImage(data.getImage(), holder.rivImage);
        } else {
            BitmapLoader.ins().loadImage("", holder.rivImage);
        }
        if (!TextUtils.isEmpty(data.getName())) {
            holder.tvTitle.setText(data.getName());
        } else {
            holder.tvTitle.setText("");
        }
        if (!TextUtils.isEmpty(data.getIntroduce())) {
            holder.tvDesc.setText(data.getIntroduce());
        } else {
            holder.tvDesc.setText("");
        }

        holder.tvPlayCount.setText(String.valueOf(data.getPlayCount()));
        holder.tvStage.setText(String.valueOf(data.getMusicCount()));
    }


    public class ViewHolder extends BaseRecyclerViewHolder {
        RatioImageView rivImage;
        TextView tvTitle;
        TextView tvDesc;
        TextView tvPlayCount;
        TextView tvStage;

        public ViewHolder(View itemView) {
            super(itemView);
            rivImage = (RatioImageView) itemView.findViewById(R.id.rivImage);
            tvTitle = (TextView) itemView.findViewById(R.id.tvTitle);
            tvDesc = (TextView) itemView.findViewById(R.id.tvDesc);
            tvPlayCount = (TextView) itemView.findViewById(R.id.tvPlayCount);
            tvStage = (TextView) itemView.findViewById(R.id.tvStage);
        }

    }


}
